<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/6/12
 * Time: 9:52
 */
namespace app\index\model;
use think\Model;

class BaseModel extends Model{

    protected static $namespace = 'app\\index\\model\\';

//    public function initialize() {
//        //设置读写分离
//        $this->setWriteConnectionService('dbWrite');
//        $this->setReadConnectionService('dbRead');
//        //不进行非空验证(不设置，在数据更新的时候，非空字段没有值(数据库default没效果)，将无法完成更新)
//        $this->setup(
//            array(
//                'notNullValidations' => false
//            )
//        );
//        $this->useDynamicUpdate(true);
//    }


    protected $result = array(
        'status' => 1,
        'msg' => '',
        'data' => []
    );

    /**
     * 设置表|模型映射
     * @param string $tableName
     */
    protected function setTableName($tableName){
        $prefix = $this->getDI()->get('config')['database']['prefix'];
        $this->setSource($prefix.$tableName);
    }


    /**
     * 加密用户密码
     * @param string    明文密码
     * @return string   加密后的密码
     */
    public function encrypt($password)
    {
        //获取salt
        $salt = $this->getDI()->get('config')['salt'];
        return hash('sha256', $salt . $password);
    }


}